from socket import *
from time import *
import random

HOST = 'localhost'
PORT = 24
BUFSIZ = 1024
ADDR = (HOST, PORT)
timeout = 1
while True:
	CliSock = socket(AF_INET, SOCK_STREAM)
	CliSock.setsockopt(SOL_SOCKET, TCP_NODELAY, 1)
	CliSock.connect(('localhost', 24))

#CliSock.send("lhlo 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n")
	response = CliSock.recv(8192)
	print "<<" + response
	lmtp_cmd = "lhlo a\r\n"
	CliSock.sendall(lmtp_cmd)
	print ">>" + lmtp_cmd

	response = CliSock.recv(8192)
	print "<<" + response

	lmtp_cmd = "mail from:<asdf>\r\nrcpt to:<asdf>\r\n"
	CliSock.sendall(lmtp_cmd, MSG_WAITALL)

	print ">>" + lmtp_cmd
	response = CliSock.recv(8192)
	print "<<" + response

	lmtp_cmd = "rset\r\n"
	CliSock.sendall(lmtp_cmd, MSG_WAITALL)

	print ">>" + lmtp_cmd
	response = CliSock.recv(8192)
	print "<<" + response


	lmtp_cmd = "mail from:<asdf>\r\nrcpt to:<asdf>\r\ndata\r\n"
	CliSock.sendall(lmtp_cmd, MSG_WAITALL)

	print ">>" + lmtp_cmd
	response = CliSock.recv(8192)
	print "<<" + response
	str = ""
	for j in range(0, random.randint(1, 5000)):
		str += ''.join(random.sample([chr(i) for i in range(48, 123)], random.randint(1, 70)))
		str += "\r\n"

	CliSock.sendall(str+"\r\n.\r\nquit\r\n")
	print ">>%d xxxxxxxxxxxxxxxxxxxxxxx\r\n.\r\nquit\r\n"%len(str)
	response = CliSock.recv(8192)
	print "<<" + response
	response = CliSock.recv(8192)
	print "<<" + response
	CliSock.close()
